//
//  CustomInfo.m
//  bmwTest
//
//  Created by Neutrino on 11-5-11.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "CustomInfo.h"

static NSString* customInfoPath = @"/Users/neutrino/CocoaSourceCode/bmwTest/cmsInfo/";
@implementation CustomInfo

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}
//-------
-(void)alertBox:(NSString*)msg
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:msg 
                                                    message:@""
                                                   delegate:self 
                                          cancelButtonTitle:@"No" 
                                          otherButtonTitles:@"Yes", nil];
    [alert show];
    [alert release];
}
-(IBAction)loadCustomInfo:(id)sender
{
    NSString* name = [textField text];
    if([name length] == 0)
    {
        [self alertBox:@"Please enter your name"];
    }
    [self displayInfo:name];
    
}
-(IBAction)loadCustomSignUp
{
    
}

-(void)displayInfo:(NSString*)name
{
    NSFileManager* fp = [NSFileManager defaultManager];
    
    for(NSString* s in [fp enumeratorAtPath:customInfoPath])
    {
        if([s isEqualToString:name])
        {
            NSMutableString* path = [[NSMutableString alloc] init];
            [path appendString:customInfoPath];
            [path appendString:name];
            [path appendString:@".txt"];
            [self readFile:path];
            [path release];
            
        }
        else
            [self alertBox:@"Sorry,we cannot find your information.New to us?"];
    }
    
}
-(void)readFile:(NSString*)filePath
{
    
}
//-------
- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
	return YES;
}

@end
